package com.yike.user.service.impl;

import com.yike.user.entity.ShopGarrisonRecord;
import com.yike.user.mapper.ShopGarrisonRecordMapper;
import com.yike.user.service.ShopGarrisonRecordService;
import com.yike.user.param.ShopGarrisonRecordPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yike.common.base.BaseServiceImpl;
import com.yike.common.pagination.Paging;
import com.yike.common.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 店铺值守记录表 服务实现类
 *
 * @author Sakura
 * @since 2024-09-06
 */
@Slf4j
@Service
public class ShopGarrisonRecordServiceImpl extends BaseServiceImpl<ShopGarrisonRecordMapper, ShopGarrisonRecord> implements ShopGarrisonRecordService {

    @Autowired
    private ShopGarrisonRecordMapper shopGarrisonRecordMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveShopGarrisonRecord(ShopGarrisonRecord shopGarrisonRecord) throws Exception {
        return super.save(shopGarrisonRecord);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateShopGarrisonRecord(ShopGarrisonRecord shopGarrisonRecord) throws Exception {
        return super.updateById(shopGarrisonRecord);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteShopGarrisonRecord(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<ShopGarrisonRecord> getShopGarrisonRecordPageList(ShopGarrisonRecordPageParam shopGarrisonRecordPageParam) throws Exception {
        Page<ShopGarrisonRecord> page = new PageInfo<>(shopGarrisonRecordPageParam, OrderItem.desc(getLambdaColumn(ShopGarrisonRecord::getCreateTime)));
        LambdaQueryWrapper<ShopGarrisonRecord> wrapper = new LambdaQueryWrapper<>();
        IPage<ShopGarrisonRecord> iPage = shopGarrisonRecordMapper.selectPage(page, wrapper);
        return new Paging<ShopGarrisonRecord>(iPage);
    }

}
